﻿@model SchoolCommunicationSystem.Models.ListPrivateMessageViewModel
@{
    ViewBag.Title = "Tin nhắn đã nhận";
    SCS.Business.MembershipService _membershipServices = new SCS.Business.MembershipService();
    string userName = User.Identity.Name;
    var user = _membershipServices.GetUser(userName);
    if (user.MembershipRoles.FirstOrDefault().roleID == 2)
    {
        Layout = "~/Views/Shared/_ParentsLayout.cshtml";
    }
    else
    {
        Layout = "~/Views/Shared/_TeacherLayout.cshtml";
    }
}
<div id="page-heading">
    <h1>Hộp Thư Đến</h1>
</div>
<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h4>@ViewBag.Title</h4>
                </div>
                <div class="panel-body">
                    @if (Model.Messages.Any())
                    {
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>Người gửi</th>
                                    <th>Tiêu đề</th>
                                    <th>Ngày gửi</th>
                                    <th>Trạng thái</th>
                                    <th>Xóa tin nhắn</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var message in Model.Messages)
                                {        
                                    <tr>
                                        <td>
                                            <strong><a href="#">@Html.Raw(message.UserFrom.userName)</a></strong>
                                        </td>
                                        <td>
                                            @Html.ActionLink(message.subject, "View", new { id = message.messageID })
                                        </td>
                                        <td>@message.dateSent.ToShortDateString()</td>
                                        @if (message.isRead == true)
                                        {
                                            <td>Đã đọc</td>
                                        }
                                        else
                                        {
                                            <td>Chưa đọc</td>
                                        }
                                        <td>
                                            <a class="editDialog" href="@Url.Action("Delete", "PrivateMessage", new { id = message.messageID })"><i class="fa fa-times"></i></a>                                            
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>

@*@Html.Pager(Convert.ToInt32(Model.PageIndex), MVCForum.Domain.Constants.AppConstants.PrivateMessageListSize, Convert.ToInt32(Model.TotalCount), new {})    *@
                    }
                    else
                    {
                        <p>Không nhận được tin nhắn nào</p>
                    }

                    <div class="btn-group">
                        @using (Html.BeginForm("SentMessages", "PrivateMessage", FormMethod.Get))
                        {@Html.AntiForgeryToken()
                            <div class="col-sm-3">
                                <button class="btn-primary btn" type="submit">Hộp thư đi</button>
                            </div>
                        }
                    </div>
                    <div class="btn-group">
                        @using (@Html.BeginForm("Create", "PrivateMessage", FormMethod.Get))
                        {@Html.AntiForgeryToken()
                            <div class="col-sm-3">
                                <button class="btn-primary btn" type="submit">Soạn tin nhắn</button>
                            </div>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


